package cookie

import (
	"strings"
	"net/http"
	"time"
)

func ParseCookie(str string) []*http.Cookie {
	cookies := make([]*http.Cookie, 0)
	sp := strings.Split(str, "; ")
	for _, s := range sp {
		valueArr := strings.Split(s, "=")
		if len(valueArr) == 2 {
			cookies = append(cookies, newHttpCookie(valueArr[0], valueArr[1]))
		}
	}
	return cookies
}

func newHttpCookie(k, v string) *http.Cookie {
	return &http.Cookie{
		Name:     k,
		Value:    v,
		Path:     "",
		MaxAge:   int(time.Hour * 24),
		HttpOnly: false,
	}
}
